package com.lagou.task03;

import java.util.Collection;
import java.util.HashMap;
import java.util.Set;

/**
 *
 * 准备一个 HashMap 集合，统计字符串"123,456,789,123,456"中每个数字字符串中出现的次数并打印出来
 *
 * */
public class HashMapTest {

    public static void main(String[] args) {

        String str = "123,456,789,123,456";
        HashMap<String,Integer> hs = new HashMap<>();

        String[] strArr = str.split(",");

        for (String eleStr : strArr) {
            if (hs.get(eleStr) != null) {
                Integer count = hs.get(eleStr);
                count++;
                hs.put(eleStr,count);
            }else {
                hs.put(eleStr, 1);
            }
        }

        Set<String> allKey = hs.keySet();
        for (String keyStr : allKey) {
            System.out.println("字符串" + keyStr + "出现了" + hs.get(keyStr) + "次");
        }

    }
}
